package chabernac.android.wordbattle.paint;

import java.util.List;

import chabernac.android.wordbattle.WordBattleView;
import chabernac.android.wordbattle.model.Letter;
import chabernac.android.wordbattle.model.Word;

public abstract class AbstractLettersDrawable extends iDrawable {
  
  protected final Word myWord;

  public AbstractLettersDrawable(Word aWord) {
    myWord = aWord;
  }
  
  protected void modifyFirstAndLastPoint(WordBattleView aWordBattleView, float[] aPoints) {
    float thePartialStretchFactor = 2.5F;
    if(aPoints.length >= 4){

      List<Letter> theLetters = myWord.getEndPointLetters();
      
      aPoints[0] -= getDirectionIndicator(theLetters.get(1).getColumn(), theLetters.get(0).getColumn()) * aWordBattleView.getWidthPerColumn() /  thePartialStretchFactor;
      aPoints[1] -= getDirectionIndicator(theLetters.get(1).getRow(), theLetters.get(0).getRow()) * aWordBattleView.getHeightPerRow() /  thePartialStretchFactor;

      int j = theLetters.size() - 2;
      aPoints[4 * j + 2] += getDirectionIndicator(theLetters.get(j+1).getColumn(), theLetters.get(j).getColumn()) *  aWordBattleView.getWidthPerColumn()  / thePartialStretchFactor;
      aPoints[4 * j + 3] += getDirectionIndicator(theLetters.get(j+1).getRow(), theLetters.get(j).getRow()) *  aWordBattleView.getHeightPerRow() / thePartialStretchFactor;
    }
  }
  
  private int getDirectionIndicator(int ap1, int ap2){
    if(ap2 > ap1) return -1;
    if(ap2 < ap1) return 1;
    return 0;
  }
}
